package com.lizheng.yunservice.goods.mapper;


import com.lizheng.yunservice.goods.model.VtpCustomerLikes;
import org.apache.ibatis.annotations.*;

@Mapper
public interface VtpCustomerLikesMapper {
    @Insert("INSERT INTO vtp_customer_likes(" +
            "customer_id, user_name, object_id, likes_type, create_time, delete_flag) " +
            "VALUES(#{customerId}, #{userName}, #{objectId}, #{likesType}, NOW(), 0)")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(VtpCustomerLikes likes);

    @Update("UPDATE vtp_customer_likes SET " +
            "delete_flag = 1,delete_time=now()" +
            "WHERE customer_id = #{customerId} AND object_id = #{objectId} " +
            "AND delete_flag = 0")
    int cancelLike(VtpCustomerLikes likes);

    @Update("UPDATE vtp_customer_likes SET " +
            "delete_flag =0, delete_time =null,update_time=now() " +
            "WHERE customer_id = #{customerId} AND object_id = #{objectId} " +
            "AND likes_type = #{likesType} AND delete_flag = 1")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int updateLike(VtpCustomerLikes likes);

    @Select("SELECT COUNT(*) FROM vtp_customer_likes " +
            "WHERE customer_id = #{customerId} AND object_id = #{objectId} " +
            "AND likes_type = #{likesType} AND delete_flag = 0")
    int existsLike(VtpCustomerLikes likes);

    @Select("SELECT COUNT(*) FROM vtp_customer_likes " +
            "WHERE customer_id = #{customerId} AND object_id = #{objectId} " +
            "AND likes_type = #{likesType} AND delete_flag = 1")
    int existsLikeRecord(VtpCustomerLikes likes);
}